<%@ page import="schoolsource.sql.SchoolDBSQL" %>
<%@ page import="schoolsource.gui.FormFields" %>
<%@ page import="schoolsource.model.UserContainer" %>
<%@ page import="schoolsource.model.Item" %>
<%@ page import="schoolsource.security.SecurityToken" %>
<%  
    SecurityToken st = (SecurityToken) request.getAttribute(FormFields.SESSION);
    String requestObject = (String) st.getValue(FormFields.TOKEN);
    UserContainer studentContainer = (UserContainer) st.removeValue("studentContainer"); 
    Item availableClassList[][] = (Item[][]) st.removeValue("availableClassList"); 
    Item assignedClassList[][] = (Item[][]) st.removeValue("assignedClassList"); 
    Item assignedTeacherList[][][] = (Item[][][]) st.removeValue("assignedTeacherList");
    Item availableParentList[][] = (Item[][]) st.removeValue("availableParentList");
    Item assignedParentList[][] = (Item[][]) st.removeValue("assignedParentList");
    int classnum = (new Integer((String) st.getValue(FormFields.CLASSNUM))).intValue();
    String editStatus = (String) st.removeValue(FormFields.EDITSTATUS);
    String displayMessage = (String) st.getValue("displayMessage"); 
    st.putValue("displayMessage", "");
    String loginType = (String) request.getAttribute(FormFields.USRTYPE); 
    String schoolName = (String) request.getAttribute(FormFields.SCHOOLNAME);
    String studentPicture = studentContainer.getPictureName().toString();
%> 



<HTML>

<HEAD>

  <title><%= (FormFields.EDITOR.equals(st.getValue(FormFields.USRTYPE)))?"Student Editor Form":"Student Profile" %></title>

    <SCRIPT LANGUAGE="JavaScript">
        function cancelForm() {
            document.forms[0].<%= FormFields.LINKCLICKED %>.value = "<%= FormFields.CANCEL %>";
            document.forms[0].submit();
        }

    </SCRIPT>
  </HEAD>
  <BODY <%= (editStatus.equals(FormFields.VIEW) ? "" : "onLoad=\"init()\"") %>>

    <FORM NAME="studenteditorform" METHOD="POST">
        <INPUT TYPE="HIDDEN" NAME="<%= FormFields.CURRENT %>" VALUE="<%= FormFields.SUBFRAME %>">
        <INPUT TYPE="HIDDEN" NAME="<%= FormFields.TOKEN %>" VALUE="<%= requestObject%>">
        <INPUT TYPE="HIDDEN" NAME="<%= SchoolDBSQL.USRTYPE %>" VALUE="<%= loginType %>">
    <INPUT TYPE="HIDDEN" NAME="<%= FormFields.SCHOOLNAME %>" VALUE="<%= schoolName %>">
        <INPUT TYPE="HIDDEN" NAME="<%= FormFields.PARAMETER %>" VALUE="<%= FormFields.EDSTUDENTPAGE %>">
        <INPUT TYPE="HIDDEN" NAME="<%= FormFields.LINKCLICKED %>" VALUE="<%= FormFields.SAVEACTION %>">
        <INPUT TYPE="HIDDEN" NAME="<%= FormFields.CLASSNUM %>" VALUE="<%= classnum %>">

        <H2>Student Profile</H2><br>
            <TABLE STYLE="font-family:sans-serif;font-size:12;" width="100%">
            <TR>
                <TH ALIGN="LEFT">Student ID</TH>
                <TD>
                <% 
                    out.println(((studentContainer!=null) ? studentContainer.getSchoolID().toString() : ""));
                %>
                </TD>
                <TD rowspan="7" ALIGN="LEFT" VALIGN="TOP">
                <%
                if (studentPicture != null && studentPicture.trim().length() != 0)
                    out.println("<IMG src=\"..\\attachments\\"+schoolName+"\\PICTURES\\"+ studentPicture +"\" width=\"100\">");
                else
                    out.println("<B>NO PHOTO<BR>AVAILABLE</B>");
                %>
                </TD>
            </TR>

            <TR>
                <TH ALIGN="LEFT">Title</TH>
                <%
                    out.println("                <TD>" + studentContainer.getTitle().toString() + "</TD>");
                %>
            </TR>

            <TR>
                <TH ALIGN="LEFT">First Name</TH>
                <%
                    out.println("<TD>" + studentContainer.getFirstName().toString() + "</TD>");
                %>
            </TR>

            <TR>
                <TH ALIGN="LEFT">Last Name</TH>
                <%
                    out.println("                <TD>" + studentContainer.getLastName().toString() + "</TD>");
                %>
            </TR>

            <TR>
                <TH ALIGN="LEFT">Phone Number</TH>
                <%
                    out.println("                <TD>" + studentContainer.getPhone().toString() + "</TD>");
                %>
            </TR>

            <TR>
                <TH ALIGN="LEFT">Email Address</TH>
                <%
                    out.println("                <TD>" + studentContainer.getEmail().toString() + "</TD>");
                %>
            </TR>
                <%
                  if (editStatus.equals(FormFields.VIEW)) {
                    out.println("            <TR>");
                    out.println("                <TH ALIGN=\"LEFT\" VALIGN=\"TOP\">Parent(s)</TH>");
                    out.println("                <TD>");
                    for (int i = 0; i < assignedParentList.length; i++) {
                        out.print(assignedParentList[i][2] + ", " + assignedParentList[i][1]);
                        out.println("<br>");
                    }
                    out.println("                </TD>");
                    out.println("            </TR>");
                    out.println("            <TR>");
                    out.println("                <TD COLSPAN=2>&nbsp;</TD>");
                    out.println("                <TD COLSPAN=2>&nbsp;</TD>");
                    out.println("            </TR>");
                    out.println("            <TR>");
                    out.println("                <TH VALIGN=\"TOP\" ALIGN=\"LEFT\">Class list</TH>");
                    out.println("                <TD colspan=\"3\">");
                    out.println("                  <TABLE STYLE=\"font-family:sans-serif;font-size:12;font-weight:normal;\">");
                    out.println("                    <TR>");
                    out.println("                      <TH ALIGN=\"LEFT\"><U>Course</U></TH>");
                    out.println("                      <TH>&nbsp;&nbsp;&nbsp;</TH>");
                    out.println("                      <TH ALIGN=\"LEFT\"><U>Class</U></TH>");
                    out.println("                      <TH>&nbsp;&nbsp;&nbsp;</TH>");
                    out.println("                      <TH ALIGN=\"LEFT\"><U>Hour</U></TH>");
                    out.println("                      <TH>&nbsp;&nbsp;&nbsp;</TH>");
                    out.println("                      <TH ALIGN=\"LEFT\"><U>Teacher</U></TH>");
                    out.println("                    </TR>");
                    for (int i = 0; i < assignedClassList.length; i++) {
                        out.println("                    <TR>");
                        out.print("<TD>");
                        out.print(assignedClassList[i][3]);
                        out.println("</TD><TD>&nbsp;</TD>");
                        out.print("<TD>");
                        out.print(assignedClassList[i][1]);
                        out.println("</TD><TD>&nbsp;</TD>");
                        out.print("<TD>");
                        out.print(assignedClassList[i][2]);
                        out.print("</TD>\n<TD>&nbsp;</TD>\n<TD>");
                        for (int j = 0; j < assignedTeacherList[i].length; j++) {
                            out.print(assignedTeacherList[i][j][2] + ", " + assignedTeacherList[i][j][1]);
                        }
                        out.println("</TD>");
                        out.println("                    </TR>");
                    }
                    out.println("                  </TABLE>");
                    out.println("                </TD>");
                    out.println("            </TR>");
                  }
/*                  else {
                    out.println("            <TR>");
                    out.println("                <TD COLSPAN=\"5\">");
                    out.println("                    <TABLE STYLE=\"font-family:sans-serif;font-size:12;\">");
                    out.println("                        <TR>");
                    out.println("                            <TD ALIGN=\"CENTER\" COLSPAN=\"2\"><H3>Parents of this child</H3></TD>");
                    out.println("                            <TD>&nbsp</TD>");
                    out.println("                            <TD ALIGN=\"CENTER\" COLSPAN=\"2\"><H3>Available parents</H3></TD>");
                    out.println("                        </TR>");
                    out.println("                        <TR>");
                    out.println("                            <TD ALIGN=\"CENTER\" COLSPAN=\"2\">");
                    out.println("                              <SELECT NAME=\"assignedParentList\" MULTIPLE=\"YES\" SIZE=\"4\"");
                    out.println("</TD>");
                    out.println("                            <TD>&nbsp;&nbsp;<INPUT TYPE=\"BUTTON\" VALUE=\"<--\" onClick='selectAvailableParent()'>&nbsp;&nbsp;<BR>");
                    out.println("                                &nbsp;<BR>");
                    out.println("                                &nbsp;&nbsp;<INPUT TYPE=\"BUTTON\" VALUE=\"-->\" onClick='unselectAssignedParent()'>&nbsp;&nbsp;</TD>");
                    out.println("                            <TD ALIGN=\"CENTER\" COLSPAN=\"2\">");
                    out.println("                              <SELECT NAME=\"availableParentList\" MULTIPLE=\"YES\" SIZE=\"4\"");
                    out.println("        ");
                    out.println("                            </TD>");
                    out.println("                        </TR>");
                    out.println("                    </TABLE>");
                    out.println("                </TD>");
                    out.println("            </TR>");
                    out.println("            <TR>");
                    out.println("                <TD COLSPAN=\"5\">");
                    out.println("                    <TABLE STYLE=\"font-family:sans-serif;font-size:12;\">");
                    out.println("                        <TR>");
                    out.println("                            <TD ALIGN=\"CENTER\" COLSPAN=\"2\"><H3>Selected Classes</H3></TD>");
                    out.println("                            <TD>&nbsp</TD>");
                    out.println("                            <TD ALIGN=\"CENTER\" COLSPAN=\"2\"><H3>Available Classes</H3></TD>");
                    out.println("                        </TR>");
                    out.println("                        <TR>");
                    out.println("                            <TD ALIGN=\"CENTER\" COLSPAN=\"2\">");
                    out.println("                              <SELECT NAME=\"assignedClassList\" MULTIPLE=\"YES\" SIZE=\"4\"");
                    out.println("</TD>");
                    out.println("                            <TD>&nbsp;&nbsp;<INPUT TYPE=\"BUTTON\" VALUE=\"<--\" onClick='selectAvailableClass()'>&nbsp;&nbsp;<BR>");
                    out.println("                                &nbsp;<BR>");
                    out.println("                                &nbsp;&nbsp;<INPUT TYPE=\"BUTTON\" VALUE=\"-->\" onClick='unselectAssignedClass()'>&nbsp;&nbsp;</TD>");
                    out.println("                            <TD ALIGN=\"CENTER\" COLSPAN=\"2\">");
                    out.println("                              <SELECT NAME=\"availableClassList\" MULTIPLE=\"YES\" SIZE=\"4\"");
                    out.println("        ");
                    out.println("                            </TD>");
                    out.println("                        </TR>");
                    out.println("                    </TABLE>");
                    out.println("                </TD>");
                    out.println("            </TR>");
                  }
*/                %>

            <TR>
                <TD COLSPAN=2>&nbsp;</TD>
                <TD COLSPAN=2>&nbsp;</TD>
            </TR>

        </TABLE>

    </FORM>
</HTML>

